load('./data/Fig2BS14.mat')

%% Fig S14
% Topological charge
[QT,QT_err] = Herror_charge(alpha_sweep,H_berry_curvature, H_berry_err);

disp(['Q_T=',num2str(QT),' +- ',num2str(QT_err)])

% Rabi oscillations
% SQ
figure
cc=[0.0549    0.2706    0.6275
    0.9020         0    0.0627
    0.0980    0.5412    0.1843
    0.9882    0.7098    0.0588];
hold on
for hlp=1:2
    for hlppm=1:2
        switch hlp
            case 1
                plot(alpha_fit/pi*180,reshape(rabi_estimate_save_SQ(hlppm,hlp,:),1,[]),'LineWidth',1.5,'Color',cc(hlp*2-2+hlppm,:),'HandleVisibility','off');
            case 2
                plot(alpha_fit/pi*180,reshape(rabi_estimate_save_SQ(hlppm,hlp,:),1,[]),'--','LineWidth',1.5,'Color',cc(hlp*2-2+hlppm,:),'HandleVisibility','off');
        end
    end
end
for hlp=1:2
    for hlppm=1:2
        switch hlp
            case {1,2}
                errorbar(alpha_sweep/pi*180,reshape(rabi_fit_save_SQ(hlppm,hlp,:,1)./E_pert_save_SQ(hlppm,hlp,:,1),1,[]),reshape(drabi_fit_save_SQ(hlppm,hlp,:,1)./E_pert_save_SQ(hlppm,hlp,:,1),1,[]),'s','MarkerSize',12,'LineWidth',1.5,'Color',cc(hlp*2-2+hlppm,:),'MarkerFaceColor',cc(hlp*2-2+hlppm,:));
            otherwise
        end
    end
end

ymax=(max(max(rabi_estimate_save(:,:,1))))+0.25;
ylim([0,ymax])
xlim([0,90])
xticks(0:15:90)
xlabel('\alpha(\circ)','FontSize',18)
ylabel('Matrix Element (MHz)','FontSize',18)
title('SQ','FontSize',20)
hold off
set(gca,'FontSize',18)

lgd=legend('$\Gamma_{\phi\alpha}$','$\Gamma_{\phi\bar{\alpha}}$','$\Gamma_{\alpha\beta}$','$\Gamma_{\alpha\bar{\beta}}$');
set(lgd,'Interpreter','latex','Location','best')
lgd.FontSize=18;

% DQ
figure
hold on
for hlp=1:4
    switch hlp
        case {1,3}
            plot(alpha_fit/pi*180,rabi_estimate_save(hlp,:,2),'LineWidth',1.5,'Color',cc(hlp,:),'HandleVisibility','off');
        case {2,4}
            plot(alpha_fit/pi*180,rabi_estimate_save(hlp,:,2),'--','LineWidth',1.5,'Color',cc(hlp,:),'HandleVisibility','off');
    end
end
for hlp=1:4
    errorbar(alpha_sweep/pi*180,rabi_fit_save(hlp,:,2)./E_pert_save(hlp,:,2),drabi_fit_save(hlp,:,2)./E_pert_save(hlp,:,2),'s','MarkerSize',12,'LineWidth',1.5,'Color',cc(hlp,:),'MarkerFaceColor',cc(hlp,:));
end

ymax=(max(max(rabi_estimate_save(:,:,2))))+0.25;
ylim([0,ymax])
xlim([0,90])
xticks(0:15:90)
xlabel('\alpha(\circ)','FontSize',18)
title('DQ','FontSize',20)
hold off
set(gca,'FontSize',18)

title('DQ','FontSize',20)
hold off
set(gca,'FontSize',18)

lgd=legend('$\Gamma_{\phi\alpha}$','$\Gamma_{\phi\bar{\alpha}}$','$\Gamma_{\alpha\beta}$','$\Gamma_{\alpha\bar{\beta}}$');
set(lgd,'Interpreter','latex','Location','best')
lgd.FontSize=18;

%% Fig2B
% plot 2-form Berry curvature

cc_g=cc;
figure
hold on
for hlp=1:2
    switch hlp
        case 1
            plot(alpha_fit/pi*180,real(F_munu_theory(hlp,:)),'LineWidth',1.5,'Color',cc_g(hlp,:),'HandleVisibility','off')
        case 2
            plot(alpha_fit/pi*180,real(F_munu_theory(hlp,:)),'--','LineWidth',1.5,'Color',cc_g(hlp,:),'HandleVisibility','off')
    end
end
for hlp=1:2
    errorbar(alpha_sweep/pi*180,F_munu_save(hlp,:),F_munu_err_save(hlp,:),'d','MarkerSize',12,'LineWidth',2,'Color',cc(hlp,:))
end
hold off
xlim([0,90]);set(gca,'XTick',[0:30:90])
xlabel('\alpha ({\circ})','FontSize',18)
ylabel('$\mathcal{F}_{\mu\nu}$','FontSize',18,'Interpreter','latex')
set(gca,'FontSize',18)
lgd=legend('$\mathcal{F}_{\phi\alpha}$','$\mathcal{F}_{\alpha\beta}$');
set(lgd,'Interpreter','latex','Orientation','horizontal')
lgd.FontSize=18;
